package com.dz.controller;

import com.dz.config.SysResult;
import com.dz.pojo.SysConfig;
import com.dz.pojoDto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.geometry.Pos;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Api("公共接口")
@RestController
@CrossOrigin
@RequestMapping("/common")
public class  CommonController {

    @Resource
    RestTemplate restTemplate;

    final String PAYMENTURL = "http://localhost:8002/common/";

    @ApiOperation("/获取配置")
    @GetMapping("/getSysConfig")
    public SysResult getSysConfig(){
        return restTemplate.getForObject(PAYMENTURL + "getSysConfig",SysResult.class);
    }


    @ApiOperation("获取服务用语")
    @GetMapping("/getServiceLanguage")
    public SysResult getServiceLanguage(){
        return restTemplate.getForObject(PAYMENTURL + "getServiceLanguage",SysResult.class);
    }

    @ApiOperation("获取采集配置文件")
    @GetMapping("/getCollectConfig")
    public SysResult getCollectConfig(){
        return restTemplate.getForObject(PAYMENTURL + "getCollectConfig",SysResult.class);
    }

    @ApiOperation("获取乡镇站点数据")
    @GetMapping("/getTownshipStation")
    public SysResult getTownshipStation(String city){
        return restTemplate.getForObject(PAYMENTURL + "getTownshipStation?city="+city,SysResult.class);
    }

    @ApiOperation("获取区域自动站站点信息")
    @GetMapping("/getSmallScaleStation")
    public SysResult getSmallScaleStation(String city){
        return restTemplate.getForObject(PAYMENTURL + "getSmallScaleStation?city="+city,SysResult.class);
    }

    @ApiOperation("获取业务制作信息")
    @GetMapping("/getJobMake")
    public SysResult getJobMake(){
        return restTemplate.getForObject(PAYMENTURL + "getJobMake",SysResult.class);
    }

    @ApiOperation("获取网格信息")
    @GetMapping("/getYbzzConfig")
    public SysResult getYbzzConfig(){
        return restTemplate.getForObject(PAYMENTURL + "getYbzzConfig",SysResult.class);
    }

    @ApiOperation("获取格点别名")
    @GetMapping("/getGridAddName")
    public SysResult getGridAddName(){
        return restTemplate.getForObject(PAYMENTURL + "getGridAddName",SysResult.class);
    }

    @ApiOperation("更新配置")
    @PostMapping("/updateSysConfig")
    public SysResult updateSysConfig(SysConfig sysConfig){
        return restTemplate.postForObject(PAYMENTURL + "updateSysConfig",sysConfig,SysResult.class);
    }

    @ApiOperation("获取文档产品的期数")
    @GetMapping("/getSysConfig1")
    public SysResult getSysConfig1(String paramName){
        return restTemplate.getForObject(PAYMENTURL + "getSysConfig1?paramName=" + paramName,SysResult.class);
    }

    @ApiOperation("更新文档产品的期数")
    @PostMapping("/updateSysConfig1")
    public SysResult updateSysConfig2(SysConfig sysConfig){
        return restTemplate.postForObject(PAYMENTURL + "updateSysConfig1",sysConfig,SysResult.class);
    }

    @ApiOperation("保存文档产品期数")
    @PostMapping("/saveSysConfig")
    public SysResult saveSysConfig(SysConfig sysConfig){
        return restTemplate.postForObject(PAYMENTURL + "saveSysConfig",sysConfig,SysResult.class);
    }

    @ApiOperation("判断点是否在多边形内")
    @PostMapping("/inPolygon")
    public SysResult inPolygon(@RequestBody InPolygonDto inPolygonDto){
        return restTemplate.postForObject(PAYMENTURL + "inPolygon",inPolygonDto,SysResult.class);
    }

    @ApiOperation("多边形求中心点")
    @GetMapping("/getCenterPoint")
    public SysResult getCenterPoint(String pointStr){
        return restTemplate.getForObject(PAYMENTURL + "getCenterPoint?pointStr=" + pointStr,SysResult.class);
    }

    @ApiOperation("兰伯特点集转换为经纬度点集")
    @GetMapping("/lbtToWgsPoints")
    public SysResult lbtToWgsPoints(String pointStr){
        System.out.println("pointStr:"+pointStr);
        return restTemplate.getForObject(PAYMENTURL + "lbtToWgsPoints?pointStr="+pointStr,SysResult.class);
    }

    @ApiOperation("获取预警内接口乡界面接口")
    @PostMapping("/getYjqCountry")
    public SysResult getYjqCountry(@RequestBody YjqQueryCountryDto yjqQueryCountryDto){
        return restTemplate.postForObject(PAYMENTURL + "getYjqCountry",yjqQueryCountryDto,SysResult.class);
    }

//    @ApiOperation("生成产品")
//    @PostMapping("/createProduct")
//    public Object createProduct(CreateProductDto createProductDto) {
//        return restTemplate.postForObject(PAYMENTURL + "getYjqCountry",createProductDto,SysResult.class);
//    }
    @ApiOperation("生成产品")
    @GetMapping("/createProduct")
    public Object createProduct(Integer issueNum,
                                String userName,
                                String yjType,
                                String sXType,
                                String date,
                                String timeChar,
                                Integer nTimes,
                                String colorAndPos,
                                String posStr,
                                MultipartFile[] images,
                                String layerName,
                                String dlData) {
//        return restTemplate.getForObject(PAYMENTURL + "getYjqCountry?issueNum=" + issueNum + "&userName=" + userName + "&yjType=" + yjType
//                + "&sXType=" + sXType + "&date=" + date + "&timeChar=" + timeChar + "&nTimes=" + nTimes + "&colorAndPos=" + colorAndPos + "&posStr=" + posStr
//                + "&images=" + images + "&layerName=" + layerName + "&dlData=" + dlData,SysResult.class);
        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("issueNum",issueNum);
        hashMap.put("userName",userName);
        hashMap.put("yjType",yjType);
        hashMap.put("sXType",sXType);
        hashMap.put("date",date);
        hashMap.put("timeChar",timeChar);
        hashMap.put("nTimes",nTimes);
        hashMap.put("colorAndPos",colorAndPos);
        hashMap.put("posStr",posStr);
        hashMap.put("images",images);
        hashMap.put("layerName",layerName);
        hashMap.put("dlData",dlData);
        return restTemplate.getForObject(PAYMENTURL + "getYjqCountry/issueNum={issueNum}&userName={userName}&yjType={yjType}&sXType={sXType}&date={date}" +
                "/timeChar={timeChar}&nTimes={nTimes}&colorAndPos={colorAndPos}&posStr={posStr}&images={images}&layerName={layerName}&dlData={dlData}",SysResult.class,hashMap);
    }

    @ApiOperation("地理分析")
    @PostMapping("/multiplePosDlfx")
    public SysResult MultiplePosDlfx(@RequestBody MultiplePosDlfxDto multiplePosDlfxDto) {
        System.out.println("ssss");
        return restTemplate.postForObject(PAYMENTURL + "multiplePosDlfx",multiplePosDlfxDto,SysResult.class);
    }

    @ApiOperation("网络请求资源")
    @PostMapping("/getImg")
    public SysResult getResource(String localResource) {
        return restTemplate.postForObject(PAYMENTURL + "getImg",localResource,SysResult.class);
    }


}
